#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
// priority_queue<int, vector<int>, less<int>> pq;

void solve() {
    int k;
    cin >> k;
    int t1 = 100000000, t2 = 1;
    int cnt = 0;
    vector<int> a, b;
    auto func = [&]()->void{
        int l = 1, r = 500;
        auto check = [&](int x) -> bool {
            int t = (x * (x - 1)) / 2;
            return t > k;
        };
        while(l < r) {
            int mid = l + r >> 1;
            if(check(mid)) r = mid;
            else l = mid + 1;
        }
        l--;
        // cout << l << endl;
        for(int i = 0; i < l; i++) {
            a.push_back(t1);
            b.push_back(t2);
            cnt++;
            t2++;
        }
        k -= (l * (l  -1)) / 2;
    };

    while(k) {
        func();
        t1--;
    }
    cout << cnt << '\n';
    for(int i = 0; i < cnt; i++){
        cout << a[i] << ' ' << b[i] << '\n';
    }
    cout << endl;
    // cout << cnt << endl;
}

signed main() {
    int t; cin >> t;
    while(t--) solve();
    return 0;
}